<?php

namespace Example\Filters;
/**
 * Copyright (C), 2021-2021, Shall Buy Life info. Co., Ltd.
 * FileName: ExampleFilter.php
 * Description: 说明
 *
 * @author lwl
 * @Create Date    2021/10/11 09:37
 * @Update Date    2021/10/11 09:37 By lwl
 * @version v1.0
 */
class ExampleFilter extends QueryFilter
{
    /**
     * FunctionName：title
     * Description：
     * Author：lwl
     * @param string $value
     * @return mixed
     */
    public function title(string $value = '')
    {
        return $this->builder->where('title', 'like', "%{$value}%");
    }

    /**
     * FunctionName：post_title
     * Description：过滤模型关联关系 post.title
     * Example 模型内 有 posts 关联关系方法
     * Author：lwl
     * @param string $value
     * @return mixed
     */
    public function post_title(string $value = '')
    {
        return $this->builder->whereHas('posts', function ($query) use ($value) {
            return $query->where('title', 'like', "%{$value}%");
        });
    }
}
